package com.qf.erp_system_admin.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.erp_system_admin.entity.Goods;
import com.qf.erp_system_admin.service.GoodsService;
import com.qf.erp_system_admin.util.R;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

/**
 * --- 天道酬勤 ---
 *
 * @author QiaoZhenWei
 * @date 2024/7/23
 * @desc --- 代码敲烂 月薪过万 ---
 */
@RestController
@RequestMapping("/nested")
public class GoodsController {
	private Logger logger = LogManager.getLogger(GoodsController.class);
	@Autowired
	private GoodsService goodsService;

	//查询全部
	@GetMapping("/list")
	public R findAll(@RequestParam HashMap<String, String> map){
		int pageNum = Integer.parseInt(map.get("pageNum"));
		int pageSize = Integer.parseInt(map.get("pageSize"));
		PageHelper.startPage(pageNum,pageSize);
		List<Goods> list = goodsService.findAll(map);
		PageInfo<Goods> info = new PageInfo<>(list);
		return R.ok(info);
	}

	//根据id删除商品
	@GetMapping("/del")
	public R del(int gdId){
		System.out.println("gdId = " + gdId);
		boolean isok = goodsService.del(gdId);
		return R.ok(isok);
	}
	//添加
	@PostMapping("/add")
	public R add(@RequestBody HashMap<String,String> map){
		boolean isok = goodsService.add(map);
		return R.ok(isok);
	}

	//商品分类查询
	@GetMapping("/findCategory")
	public R findCategory(){
		List<String> list = goodsService.findCategory();
		return R.ok(list);
	}

}
